home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
pc
/
files
/
t_unix
/
bs941029.tgz
/
bbsx-941029.tar
/
bbsx
/
genpasswd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-29
|
1KB
|
69 lines
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
int get_passwd(char *filename, char *timestamp, char *password)
{
int fd;
int offset;
int min, hour, day;
char buf[1024];
int i;
if ((fd=open(filename,O_RDONLY)) == -1) {
perror("file not found");
exit(0);
}
if (strlen(timestamp) != 10) {
perror("format error in timestring");
exit(0);
}
strncpy(buf, timestamp, 2); buf[2] = '\0';
day = atoi(buf);
strncpy(buf, ×tamp[6], 2); buf[2] = '\0';
hour = atoi(buf);
strncpy(buf, ×tamp[8], 2); buf[2] = '\0';
min = atoi(buf);
offset = ((min + day) % 60) * 27 + hour;
if (hour > 23) exit(0);
if(lseek(fd, (long) (offset), SEEK_SET) == -1) exit(0);
if(read(fd, password, 4) < 1) exit(0);
password[4] = '\0';
close(fd);
return 1;
}
main(int argc, char **argv)
{
FILE *fp;
char filename[1024];
char timestring[1024];
char password[1024];
if (argc > 1) {
sprintf(filename,"/users/bbs/%s.pwd",argv[1]);
} else {
printf("Enter passwordfile-name: ");
gets(filename);
}
printf("Enter Timestring: ");
gets(timestring);
get_passwd(filename, timestring, password);
printf("Password is: %s\n", password);
return 0;
}